package com.yuxi.al.sort;


/**
 * Created by yuxi on 17/2/5.
 */
public class BubbleSort {
    public static void main(String[] args) {
        //冒泡排序
        int[] arr = {2, 3, 1, 33, 2, 4, 56, 42, 3, 21, 6, 7, 5};
        bubbleSort(arr);
        //排序后
        for (int i = 0; i <arr.length ; i++) {
            System.out.print(arr[i]+" ");
        }
    }

    private static void bubbleSort(int[] arr) {
        for (int i = arr.length-1; i >=0 ; i--) {
            for (int j = 0; j <i ; j++) {
                if (arr[j]>arr[j+1]){
                    int tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                }
            }
        }
    }
}
